package demo1;

public class demo_04threadName {
    public static void main(String[] args) {
        //创建一个自己给名字的线程
        Thread thread1 =new Thread(()->{
            while (true){
                //Thread.currentThread()用于获取当前运行的线程对象的引用.
                System.out.println("线程名字： "+Thread.currentThread().getName()+" 正在运行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"我是你创建的线程");
        //创建默认名字的线程
        Thread thread2 =new Thread(()->{
            while (true){
                //Thread.currentThread()用于获取当前运行的线程对象的引用.
                System.out.println("线程名字： "+Thread.currentThread().getName()+" 正在运行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        //启动线程
        thread1.start();
        thread2.start();
    }
}
